package com.zzq.my.jetpacks.jectpackapp.ui.act

import android.view.View
import android.widget.ArrayAdapter
import androidx.viewpager.widget.ViewPager
import by.kirich1409.viewbindingdelegate.viewBinding
import com.aisier.architecture.base.BaseActivity
import com.zzq.my.jetpacks.jectpackapp.R
import com.zzq.my.jetpacks.jectpackapp.adapter.ViewPagerAdapter
import com.zzq.my.jetpacks.jectpackapp.databinding.ActivityVpBinding
import com.zzq.my.jetpacks.jectpackapp.view.FixListView


/**
 * 描述：viewpage view 嵌套list滑动冲突解决
 * 作者：zhuangzeqin
 * 时间: 2022/1/18-17:04
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class Activity11 : BaseActivity(R.layout.activity_vp), View.OnClickListener {
    private val binding by viewBinding(ActivityVpBinding::bind)

    private lateinit var mListData: MutableList<String>

    private lateinit var mViews: ArrayList<View>

    private lateinit var mViewPagerAdapter: ViewPagerAdapter

    var names = arrayOf("a", "b", "c")


    /**
     * 初始化数据
     */
    override fun initData() {
        mViews = arrayListOf()
        mListData = mutableListOf()
        for (i in 0..50) {
            mListData.add("data$i")
        }


        for (i in 0..3) {
            //初始化listView
            val listView = FixListView(this)
            //初始化adapter
            val adapter: ArrayAdapter<String> = ArrayAdapter<String>(mContext, R.layout.item_text1,R.id.tv_info, mListData)
            listView.adapter =adapter
            mViews.add(listView)
        }
        mViewPagerAdapter = ViewPagerAdapter(mViews)
        binding.vp1.adapter = mViewPagerAdapter
        binding.vp1.addOnPageChangeListener(object :ViewPager.OnPageChangeListener{

            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }


            override fun onPageSelected(position: Int) {
                binding.atvTitl.text = "当前的索引$position"
            }


            override fun onPageScrollStateChanged(state: Int) {

            }
        })

        //kotlin  for  循环的是几种方式
//        //1
//        for (name in names)
//            println("3 $name")
//        //2
//        for (i in names.indices)
//            println("4 $i $names[i]")
//        //3
//        for ((index, name) in names.withIndex())
//            println("5 $index $name")
    }

    /**
     * 初始化操作
     */
    override fun initView() {

    }


    /**
     * 初始化点击事件操作
     */
    override fun eventOnClick() {

    }

    override fun onClick(v: View) {

    }

}